/*Entry Cost Analysis
STATA 14
August 18, 2017
Country-Level Balance Tests*/


cd  "C:\Users\ejm5\Dropbox\Rents_Asunder\CountryofOrigin\20160315_InternationaOrganization\Replication"
use  oecd_7years_final.dta, clear
log using balance.smcl, replace
set more off


use "oecd_7years_working.dta", clear
collapse oecd, by(ccodecow a1)
drop if ccodecow==.
rename a1 year
xtset ccodecow year
save oecd_id.dta, replace


use "QoG_2016_ts.dta", clear
xtset ccodecow year
merge 1:1 ccodecow year using oecd_id.dta
drop if _merge!=3

replace unna_pop=unna_pop/1000000
replace wdi_gdpcon= wdi_gdpcon/1000000000
drop if year<2005

/*****************************Table A1*************************************************************************************************************/



/*ALl Countries*/
#delimit;
set more off;
foreach x in ajr_settmort chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon 
{;
ttest `x', by(oecd);
scalar define t_mean_`x'= r(mu_2);
scalar define c_mean_`x'= r(mu_1);
scalar define t_sd_`x'= r(sd_2);
scalar define c_sd_`x'= r(sd_1);
scalar define p_`x'=r(p);
scalar define t_`x'=r(t);
};

collapse ccodecow;

#delimit;
set more off;
foreach x in ajr_settmort chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon 
{;
generate t_mean_`x'= t_mean_`x';
generate c_mean_`x'= c_mean_`x';
generate t_sd_`x'= t_sd_`x';
generate c_sd_`x'= c_sd_`x';
generate p_`x'=p_`x';
generate t_`x'=t_`x';
};

#delimit;
drop ccodecow;
generate id=_n;
reshape long t_mean_ t_sd_ c_mean_ c_sd_ p_ t_, i(id) j(var) string;
drop if t_mean==.;
replace id=_n;
save ttest_OECD.dta, replace;

#delimit;
use  "QoG_2016_ts.dta", clear;

keep ajr_settmort chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon ;

order ajr_settmort chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon ;

describe, replace clear;
drop type isnumeric format vallab;
rename name var;
sort var;

merge 1:1 var using ttest_OECD.dta;
sort position;

outsheet using "ttest_OECD", comma replace;






/*Big 4*/

use "oecd_7years_working.dta", clear;
#delimit;
collapse oecd country_id, by(ccodecow a1);
drop if ccodecow==.;
rename a1 year;
xtset ccodecow year;
save oecd_id.dta, replace;

#delimit;
use "QoG_2016_ts.dta", clear;

xtset ccodecow year;
merge 1:1 ccodecow year using oecd_id.dta;
drop if _merge!=3;

replace unna_pop=unna_pop/1000000;
replace wdi_gdpcon= wdi_gdpcon/1000000000;
drop if year<2005;


#delimit;
keep if country_id==25|country_id==50|country_id==47|country_id==56;


set more off;
foreach x in  chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon 
{;
ttest `x', by(oecd);
scalar define t_mean_`x'= r(mu_2);
scalar define c_mean_`x'= r(mu_1);
scalar define t_sd_`x'= r(sd_2);
scalar define c_sd_`x'= r(sd_1);
scalar define p_`x'=r(p);
scalar define t_`x'=r(t);
};

collapse ccodecow;

#delimit;
set more off;
foreach x in chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon 
{;
generate t_mean_`x'= t_mean_`x';
generate c_mean_`x'= c_mean_`x';
generate t_sd_`x'= t_sd_`x';
generate c_sd_`x'= c_sd_`x';
generate p_`x'=p_`x';
generate t_`x'=t_`x';
};

#delimit;
drop ccodecow;
generate id=_n;
reshape long t_mean_ t_sd_ c_mean_ c_sd_ p_ t_, i(id) j(var) string;
drop if t_mean==.;
replace id=_n;
save ttest_OECD.dta, replace;

#delimit;
use  "QoG_2016_ts.dta", clear;

keep  chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon ;

order  chga_demo fh_fotpsc5 fh_cl fh_pr h_polcon3 p_polity2 ti_cpi undp_hdi unna_pop wbgi_cce wdi_expgsgdp wdi_expaggrw wdi_fdiin wdi_fdiout wdi_gdpcon wdi_gdpgr wdi_gdppccon wdi_gdppcpppcon ;

describe, replace clear;
drop type isnumeric format vallab;
rename name var;
sort var;

merge 1:1 var using ttest_OECD.dta;
sort position;

outsheet using "ttest_OECD_Big4", comma replace;
log close;
















